package org.example.testcode.DelayedQueue;

import java.util.Date;
import java.util.concurrent.DelayQueue;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class DelayQueueDemo {

    public static void main(String[] args) {
        DelayQueue<DelayedItem<String>> queue = new DelayQueue<DelayedItem<String>>();
        queue.offer(new DelayedItem<String>(10000L, "A"));
        System.out.printf("[%s] produce message A\r\n", System.currentTimeMillis() + ":" + new Date());
        queue.offer(new DelayedItem<String>(20000L, "B"));
        System.out.printf("[%s] produce message B\r\n", System.currentTimeMillis() + ":" + new Date());

        ExecutorService executorService = Executors.newCachedThreadPool();
        executorService.execute(new Consumer(queue));
        executorService.shutdown();
    }
}